/**
 * @file disp_driver.h
 */

#ifndef DISP_DRIVER_H
#define DISP_DRIVER_H

#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif

/*********************
 *      INCLUDES
 *********************/

#include "lvgl.h"

#include <stdio.h>

#include "gpio.h"
#include "spi.h"

#include "st7789.h"
#include "gc9a01.h"
#include "st7735.h"

/*********************
 *      DEFINES
 *********************/

/**********************
 *      TYPEDEFS
 **********************/

typedef struct {
    // panel config
    const char *disp_path;
    const char *disp_ic;
    // pin config
    int pin_cs;
    int pin_dc;
    int pin_rst;
    int bl_pwm;
    // spi config
    int spi_speed_mh;
    int spi_mode;
    // resolution config
    int offset_x;
    int offset_y;
    int width;
    int height;
    int orientation;
} configuration;

/*The LCD needs a bunch of command/argument values to be initialized. They are
 * stored in this struct. */
typedef struct {
    uint8_t cmd;
    uint8_t data[16];
    uint8_t databytes; // No of data in data; bit 7 = delay after set; 0xFF =
                       // end of cmds.
    uint8_t delaytime; // delaytime
} lcd_init_cmd_t;

typedef struct {
    void (*disp_set_window)(lv_disp_drv_t *drv, const lv_area_t *area);
    void (*disp_set_orientation)(uint8_t orientation);
    lcd_init_cmd_t *disp_init_cmd;
} disp_driver_api;
/**********************
 * GLOBAL PROTOTYPES
 **********************/

/* Initialize display */
void disp_driver_init(void);
void disp_send_cmd(uint8_t cmd);
void disp_send_data(void *data, uint16_t length);

/* Display flush callback */
void disp_driver_flush(lv_disp_drv_t *drv, const lv_area_t *area,
                       lv_color_t *color_p);
void lcd_clear(uint16_t color);

/**********************
 *      MACROS
 **********************/

#ifdef __cplusplus
} /* extern "C" */
#endif

#endif /*DISP_DRIVER_H*/